package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/car-pooling/
 * @create 2025/8/23 15:44
 * @since JDK17
 */

public class Solution46 {
    public boolean carPooling(int[][] trips, int capacity) {
        int n = trips.length, sum = 0;
        int[] diff = new int[1002];
        for (int i = 0; i < n; i++) {
            diff[trips[i][1]] += trips[i][0];
            diff[trips[i][2] + 1] -= trips[i][0];
        }
        for (int i = 0; i <= 1000; i++) {
            sum += diff[i];
            if (sum > capacity) {
                return false;
            }
        }

        return true;
    }
}
